package org.ysu.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ysu.common.JsonResult;
import org.ysu.pojo.*;
import org.ysu.service.ClueService;
import org.ysu.service.VerifierService;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/clue")
public class ClueController {
    @Autowired
    public ClueService clueService;
    @Autowired
    private VerifierService verifierService;

    @RequestMapping("/insert")
    public JsonResult insert(@RequestBody  Clue clue) {
        clue.setCreateTime(new Date());
        //插入一条记录
        Integer id=clueService.insertClue(clue);
        JsonResult result=new JsonResult<>(id>0?1:0,id>0?"success":"fail",null);
        return  result;
    }

    @GetMapping("/getListByccId/{id}")
    public List<Clue> getCLue(@PathVariable Integer id) {
        return clueService.getListsByCcid(id);
    }

    @GetMapping("/getListByvId/{vid}")
    public List<Clue> getCLueByVid(@PathVariable Integer vid) {
        return clueService.getListsByVid(vid);
    }

    @GetMapping("/changeRisk/{id}/{riskMan}/{riskSubstance}/{riskNature}/{riskFinance}/{riskSocial}")
    public JsonResult changeRisk(@PathVariable  Integer id, @PathVariable Integer riskMan, @PathVariable Integer riskSubstance, @PathVariable Integer riskNature, @PathVariable Integer riskFinance, @PathVariable Integer riskSocial)
    {
        System.out.println(id+" "+riskMan+" "+riskSubstance+" "+riskNature+" "+riskFinance+" "+riskSocial);
        Date date1=new Date();
        System.out.println(date1);
        Integer result=clueService.changeRisk(id, riskFinance, riskSocial, riskMan, riskSubstance, riskNature,date1);
        if(result==0){
            return new JsonResult<>(0,"改变失败",result);
        }
        else {
            return new JsonResult<>(0,"改变成功",result);
        }
    }

    @GetMapping("/get/ver/{idNumber}")//身份证号
    public List<ClueAndPName> getClueByvId(@PathVariable String idNumber){
        String s=idNumber;
        Verifier verifier=verifierService.findByIdNumber(s);
        if(verifier==null){
            return null;
        }
        Integer vid=verifier.getVId();
        List<ClueAndPName> clueByvId = clueService.getClueByvId(vid);
        if (clueByvId.size() == 0) {
            return null;
        }
        return clueByvId;
    }

}


